<?php
use Carbon\Carbon;
class ProductComponent extends Eloquent {
	
	protected $table = 'products_components';
	
	public function component() {
		return $this->belongsTo('Component');
	}
	
	public function product() {
		return $this->belongsTo('Product');
	}
	
	public static function whereProductWithComponents($productId) {
		return ProductComponent::where('product_id', '=', $productId)->with(array(
			'component' => function($query) {
				$query->orderBy('code', 'asc')->orderBy('name', 'asc');
			},
			'product'
		));
	}
	
}